<template>
    <div class="page" data-page="mine" style="z-index: 2;">
        <div class="link-page-nav">
            <a href="#" class="link back">
                <i class="iconfont icon-zuo"></i>
            </a>
        </div>
        <div class="link-page-top" style="padding-bottom: 17px;">
            <div class="link-page-title">修改密码</div>
        </div>
        <div class="page-content modPassWord">
            <div class="list inline-labels no-hairlines-md" style="margin: 20px 0px;">
                <ul>
                    <li class="item-content item-input">
                        <div class="item-inner">
                            <div class="item-title item-label" style="width: 23%">原密码</div>
                            <div class="item-input-wrap">
                                <input type="password" id="oldPass" placeholder="请输入原密码" >
                            </div>
                        </div>
                    </li>
                    <li class="item-content item-input">
                        <div class="item-inner">
                            <div class="item-title item-label" style="width: 23%">新密码</div>
                            <div class="item-input-wrap">
                                <input type="password" id="newPass" placeholder="请输入新密码">
                            </div>
                        </div>
                    </li>
                    <li class="item-content item-input">
                        <div class="item-inner">
                            <div class="item-title item-label" style="width: 23%">再次输入</div>
                            <div class="item-input-wrap">
                                <input type="password" id="tooNewPass" placeholder="再次输入新密码">
                            </div>
                        </div>
                    </li>
                </ul>
            </div>

            <div class="block">
                <div class="myrow">
                    <a href="#" class="col button button-fill mybutton-round"  @click="saveModPw">确定</a>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    return {
        // Component Methods
        methods: {
            //确定
            saveModPw: function () {
                var app = this.$app;
                var oldPass = $("#oldPass").val();
                var newPass = $("#newPass").val();
                var tooNewPass = $("#tooNewPass").val();
                var myReg = /^[a-zA-Z0-9_]{0,}$/;
                if (oldPass == "") {
                    app.methods.showToastBottom('旧密码不能为空');
                    return;
                }
                if (newPass == "" || tooNewPass == "") {
                    app.methods.showToastBottom('新密码不能为空');
                    return;
                }
                if (newPass != tooNewPass) {
                    app.methods.showToastBottom('两次输入新密码不一致');
                    return;
                }
                if (jQuery.md5(oldPass).toUpperCase() != userInfor.password){
                    app.methods.showToastBottom('旧密码不正确');
                    return;
                }
                if(newPass.length<6 ||tooNewPass.length<6){
                    app.methods.showToastBottom("密码不低于6位")
                    return;
                }
                if(newPass.length>16 ||tooNewPass.length>16){
                    app.methods.showToastBottom("密码不高于16位")
                    return;
                }
                if(String(newPass).indexOf(" ")!=-1 || String(tooNewPass).indexOf(" ")!=-1){
                    app.methods.showToastBottom("密码不能包含空格")
                    return;
                }
                common.loading(1);
                Dao.modifyPw({
                        userName: userInfor.accountName,
                        deviceId: appKeyObj.deviceId,
                        userId: userInfor.id,
                        oldPassword: userInfor.password,
                        newPassword:jQuery.md5(newPass).toUpperCase(),
                },function(data){
                      common.loading(0);
                      app.methods.showToastBottom('修改密码成功');
                      userInfor.password = jQuery.md5(newPass).toUpperCase();
                      native.saveDataByKey('password',newPass);
                      app.router.back();
                },function(e) {
                      common.loading(0);
                      app.methods.showToastBottom('修改密码失败');
                });
            },
        },
    }
</script>

<style scoped>
    .myrow{
        margin-left: 25px;
        margin-right: 25px;
    }
     .title{
         padding-right: 56px;
         margin: 0px auto;
     }
     .mybutton-round{
         border-radius: 6px;
         font-size: 16px;
         background-image: linear-gradient(to top, #238afb, #40affe);
     }
</style>